package com.example.study.design.strategy;

import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略工厂
 *
 * @author duckquan
 */
@NoArgsConstructor
public class GoodsHandleStrategyFactory {

    //使用Map集合存储策略信息，彻底消除if...else
    private static Map<String, GoodsHandleStrategy> strategyMap;

    //初始化具体策略，保存到map集合
    public static void init() {
        strategyMap = new HashMap<>();
        strategyMap.put("MT001", new Mt001GoodsHandleStrategy());
        strategyMap.put("MT002", new Mt002GoodsHandleStrategy());
    }

    //根据产品线code获取对应策略对象
    public static GoodsHandleStrategy getGoodsHandleStrategy(String productCode) {
        return strategyMap.get(productCode);
    }

}
